cmake_minimum_required(VERSION 3.14)

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19")
    cmake_policy(SET CMP0110 NEW)
endif()

find_program(CLANGPP clang++)
if(CLANGPP)
    message(STATUS "Found clang++: " ${CLANGPP})
    set(CMAKE_CXX_COMPILER ${CLANGPP})
endif(CLANGPP)

find_program(CCACHE ccache)
if(CCACHE)
    message(STATUS "Found ccache: " ${CCACHE})
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
endif(CCACHE)

project(fuck_leet_code LANGUAGES CXX)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

find_package(Eigen3 REQUIRED NO_MODULE)

include(FetchContent)
set(CATCH_BUILD_TESTING OFF CACHE INTERNAL "")
set(CATCH_INSTALL_DOCS OFF CACHE INTERNAL "")
set(CATCH_INSTALL_HELPERS OFF CACHE INTERNAL "")
FetchContent_Declare(catchorg.Catch2
    GIT_REPOSITORY https://gitee.com/mirrors/Catch2.git
    GIT_TAG        v2.13.0
    GIT_SHALLOW    TRUE)
FetchContent_MakeAvailable(catchorg.Catch2)

add_compile_options(-fdiagnostics-color=always -pedantic -Wall -Wextra -O0 -ggdb3)

file(GLOB TEST_SOURCES
    ${CMAKE_CURRENT_LIST_DIR}/002_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/003_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/005_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/006_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/007_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/008_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/009_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/010_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/011_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/012_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/013_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/015_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/016_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/017_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/018_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/019_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/020_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/022_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/023_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/024_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/025_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/028_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/029_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/030_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/031_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/032_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/033_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/034_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/036_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/037_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/039_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/040_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/041_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/042_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/043_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/044_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/045_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/046_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/047_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/048_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/049_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/050_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/051_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/052_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/053_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/054_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/055_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/056_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/057_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/059_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/060_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/061_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/062_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/063_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/064_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/068_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/069_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/070_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/071_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/072_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/073_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/074_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/075_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/076_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/077_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/078_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/079_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/080_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/081_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/082_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/084_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/085_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/086_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/089_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/090_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/091_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/092_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/093_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/094_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/095_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/096_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/097_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/098_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/099_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/144_**/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/145_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/224_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/268_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/287_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/295_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/429_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/590_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/838_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/1024_**/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/pinduoduo/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/quick_sort/test.cpp
    ${CMAKE_CURRENT_LIST_DIR}/binary_tree.hpp/test.cpp

    ${CMAKE_CURRENT_LIST_DIR}/test.cc)

file(GLOB JIANZHI_OFFER_SOURCES ${CMAKE_CURRENT_LIST_DIR}/jianzhi_offer/*.cpp)
file(GLOB JIANZHI_OFFER_SOURCES ${CMAKE_CURRENT_LIST_DIR}/jianzhi2/*.cpp)

enable_testing()

add_executable(fuck_leet_code)
target_compile_features(fuck_leet_code PRIVATE cxx_std_17)
target_compile_options(fuck_leet_code PRIVATE -Wno-sign-compare -Wno-unused-function)
target_include_directories(fuck_leet_code PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(fuck_leet_code PRIVATE Eigen3::Eigen Catch2::Catch2)
target_sources(fuck_leet_code PRIVATE ${TEST_SOURCES} ${JIANZHI_OFFER_SOURCES})

include(${catchorg.catch2_SOURCE_DIR}/contrib/ParseAndAddCatchTests.cmake)
ParseAndAddCatchTests(fuck_leet_code)
